﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TeaClass
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Tea price list shoud be filled by manager!");
            Console.ReadKey();
            string ch = "n";
            List<Tea> teaList = new List<Tea>();
            do
            {
                Console.Clear();
                Tea newTea = new Tea();
                newTea.FillTeaInfo();
                teaList.Add(newTea);
                Console.WriteLine();
                Console.WriteLine("Do you want to add new tea? y/n");
                ch = Console.ReadLine().ToLower();
            } while (ch == "y");

            
            do
            {
                Console.Clear();
                Console.WriteLine("User menu:");
                Console.WriteLine("Use buttons 1-3 to choose the operation");
                //Console.WriteLine("1 - Fill tea price list (!!! Only for personel !!!)");
                Console.WriteLine("1 - Search by producer country");
                Console.WriteLine("2 - Choose tea from list, enter weight and get finish price");
                Console.WriteLine("3 - Print tea price list");
                int choose = Int32.Parse(Console.ReadLine());
                switch (choose)
            {
                
                case 1:
                        SearchByCountry(teaList);
                    break;
                case 2:
                        CalculatePriceForUsersChose(teaList);
                    break;
                case 3:
                        PrintTeaList(teaList);
                    break;
                default:
                    Console.WriteLine("Error!");
                    break;
            }
            Console.WriteLine("Do you want to continue? y/n");
            ch = Console.ReadLine().ToLower();
        } while (ch == "y");

        }

        //static List<Tea> FillTeaList()
        //{
        //    string ch = "n";
        //    List<Tea> teaList = new List<Tea>;
        //    do
        //    {
        //        Tea newTea = new Tea();
        //        newTea.FillTeaInfo();
        //        teaList.Add(newTea);
        //        Console.WriteLine("Do you want to add new tea? y/n");
        //        ch = Console.ReadLine().ToLower();

        //        return teaList;
        //    } while (ch == "y");
        //}

        static void PrintTeaList(List<Tea> newTeaList)
        {
            Console.Clear();
            foreach(var newTea in newTeaList)
            {
                Console.WriteLine("Tea #{0}", (newTeaList.IndexOf(newTea) + 1));
                newTea.PrintteaInfo();
                Console.WriteLine();
            }
        }

        static void SearchByCountry (List<Tea> newTeaList)
        {
            Console.Clear();
            Console.Write("Enter producer country: ");
            string userContryChoice = Console.ReadLine();
            foreach (var newTea in newTeaList)
            {
                if (userContryChoice==newTea.producerCountry)
                {
                    Console.WriteLine("Tea #{0}", (newTeaList.IndexOf(newTea)+1));
                    newTea.PrintteaInfo();
                    Console.WriteLine();
                }

            }
        }

        static void CalculatePriceForUsersChose(List<Tea> newTeaList)
        {
            Console.Clear();
            double finishPrice = 0;
            PrintTeaList(newTeaList);
            Console.Write("Choose tea (enter number from the list): ");
            int userNumberChoice = Int32.Parse(Console.ReadLine());
            Console.Write("Enter amount of tea you want to buy, g: ");
            int enteredWeight = Int32.Parse(Console.ReadLine());
            foreach (var newTea in newTeaList)
            {
                if ((userNumberChoice - 1) == newTeaList.IndexOf(newTea))
                {
                    double priceForGramm = newTea.priceFor100G / 100;
                    Console.WriteLine(priceForGramm);
                    Console.ReadKey();
                    finishPrice =(newTea.priceFor100G * enteredWeight) / 100;
                    Console.WriteLine("Finish price is {0} $ for {1} g of chosen tea", finishPrice, enteredWeight);
                }
            }

        }

    }
}

